﻿@model ProfileVisaModel
@{
	ViewBag.Title = Resources.ConferenceVisa + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.FullName：<input id="selUserName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConferenceVisa" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01"></h3>
			<form id="frmDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">Last Name：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="v-familyname" name="familyName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true" disabled="disabled" />
							<input type="hidden" id="conferenceAttendId" name="conferenceAttendId" />
							<input type="hidden" id="hidID" name="Id" />
							<input type="hidden" id="hidConferenceId" name="conferenceId" />
						</td>
						<td style="text-align: right;" class="w1 c1">First Name：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="v-firstname" name="firstName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true" disabled="disabled" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">Title：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-title" name="title" class="easyui-combobox" style="height:27px; width:300px;" data-options="required:true,editable:false" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c3">Affiliation：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-affiliation" name="affiliation" class="easyui-textbox" style="height:27px; width:300px;" disabled="disabled" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">Country：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="v-country" name="country" class="easyui-combobox" style="height:27px; width:300px;" data-options="required:true" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c1"></td>
						<td style="text-align: left;" class="w2 c2"></td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">State/Province：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-state" name="state" class="easyui-combobox" style="height:27px; width:300px;" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c3"></td>
						<td style="text-align: left;" class="w2 c4"></td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">City：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="v-city" name="city" class="easyui-combobox" style="height:27px; width:300px;" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c1"></td>
						<td style="text-align: left;" class="w2 c2"></td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">Zip/Postal Code：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-postcode" name="zipCode" class="easyui-textbox" style="height:27px; width:300px;" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c3"></td>
						<td style="text-align: left;" class="w2 c4"></td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">Address：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="v-address" name="address" class="easyui-textbox" style="height:27px; width:88%;"  disabled="disabled" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">Email：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-email" name="mail" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['email','length[1,30]']" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c3">Telephone：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-telephone" name="telephone" class="easyui-textbox" style="height:27px; width:300px;" disabled="disabled" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">Birthdate：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="v-birthdate" name="birthday" class="easyui-datebox" style="height:27px; width:300px;" data-options="editable:false,required:true" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c1">Gender：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="v-gender" name="gender" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'" disabled="disabled">
								<option value="Male">Male</option>
								<option value="Female">Female</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">Passport No.：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-passportNum" name="passportNum" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c3">Passport Issue Country：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-countryOfIssue" name="countryOfIssue" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true" disabled="disabled" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">Passport Issue Date：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="v-issueDate" name="issueDate" class="easyui-datebox" style="height:27px; width:300px;" data-options="editable:false,required:true" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c1">Passport Expiry Date：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="v-expiryDate" name="expiryDate" class="easyui-datebox" style="height:27px; width:300px;" data-options="editable:false,required:true" disabled="disabled" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">Arrival Date：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-arrivalDate" name="arrivalDate" class="easyui-datebox" style="height:27px; width:300px;" data-options="editable:false,required:true" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c3">Departural Date：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="v-departuralDate" name="departuralDate" class="easyui-datebox" style="height:27px; width:300px;" data-options="editable:false,required:true" disabled="disabled" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="v-remark" name="remark" class="easyui-textbox" disabled style="height:50px; width:88%;" data-options="multiline:true, validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Close" />
			</div>
		</div>
	</div>
</div>
<div id="uploadWindow" class="easyui-window"
	title="@Resources.Upload" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:600px; display:none;">
	<div class="popupDiv">
		<form id="uploadDetail" method="post" enctype="multipart/form-data" action="@Url.Action(nameof(ConferenceVisaController.Upload), nameof(ConferenceVisaController).GetControllerName())">
			@Html.AntiForgeryToken()
			<input type="hidden" id="hiddenID" name="Id" />
			<input type="hidden" id="attendenceId" name="attendenceId" />
			<input type="hidden" id="conferenceId" name="conferenceId" />
			<input id="invitation" name="invitationFile" class="easyui-filebox" style="height:27px; width:500px;" data-options="required:true, prompt:'@Resources.UploadFile', buttonText:'@Resources.ChooseFile'" />
		</form>
		<div class="buttonDiv">
			<input type="button" onclick="uploadFile();" class="lbtn" value="@Resources.Upload" />&nbsp;&nbsp;
			<input type="button" class="rbtn" onclick="$('#uploadWindow').window('close');" value="@Resources.Close" />
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceVisa");
	common.setCurrentParentMenu("#menu_a1");

	var windowWidth = $(window).width() - 285;
	var windowHeight = $(window).height() - 110;

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");

		$("#selUserName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceVisaController.GetData),
					nameof(ConferenceVisaController).GetControllerName())",
			method: "get",
			singleSelect: true,
			fitColumns: false,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			frozenColumns: [[
				{ field: "id", title: "ID", hidden: true },
				{ field: "attendenceId", title: "AttendenceId", hidden:true},
				{ field: "conferenceId", title: "ConferenceId", hidden:true},
					@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
						Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.ConferenceVisa, RoleType.修改) ||
						Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.ConferenceVisa, RoleType.删除))
					{
						<text>
						{
							field: "operate", title: "@Resources.Operate", align: "center", width: 250,
							formatter: function(value, rec) {
								var strInfo = "";
								var tmp = rec.firstName == null ? "" : rec.firstName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
								@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.ConferenceVisa, RoleType.浏览))
								{
									<text>
									if (rec.invitation != null) {
										if (/\.(pdf|PDF)$/.test(rec.invitation)) {
											strInfo +="<a href='"+rec.invitation+"' class='downloadLink' target='_blank'>";
											strInfo +="<img src='~/Images/icon_25.png' width='18px' style='position:relative; top:4px;'></a>";
										} else {
											strInfo += "<img src='~/Images/icon_25.png' width='18px' style='position:relative; top:4px;'/>";
										}
									}
									strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='lookup(\""
										+ rec.attendenceId + "\",\"" + tmp + "\")'>@Resources.Lookup</a>";
									</text>
								}
								@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.ConferenceVisa, RoleType.修改))
								{
									<text>
									if (strInfo != "") {
										strInfo += "&nbsp;|&nbsp;";
									}
									strInfo += "<a href='#' style='color:#FF8C00;font-weight:bold;text-decoration:underline;' onclick='upload(\""
										+ rec.id + "\",\"" + rec.attendenceId + "\",\"" + rec.conferenceId + "\")'>@Resources.Upload</a>";
									</text>
								}
								@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.ConferenceVisa, RoleType.删除))
								{
						    			<text>
									if (strInfo != "") {
										strInfo += "&nbsp;|&nbsp;";
									}
									strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
										+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
									</text>
								}
								@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.ConferenceVisa, RoleType.修改))
								{
									<text>
									if (strInfo != "") {
										strInfo += "&nbsp;|&nbsp;";
									}
									strInfo += "<a href='#' style='color:#1874CD;font-weight:bold;text-decoration:underline;' onclick='send(\""
										+ rec.id + "\",\"" + tmp + "\",\"" + rec.conferenceId + "\")'>@Resources.Send</a>";
									</text>
								}
								return strInfo;
							}
						},
					</text>
				},
			]],
			columns: [[
				{ field: "familyName", title: "@Resources.FamilyName", align: "center", sortable: true, width: 150 },
				{ field: "firstName", title: "@Resources.FirstName", align: "center", sortable: true, width: 150 },
				{ field: "title", title: "@Resources.Title", align: "center", sortable: true, width: 150 },
				{ field: "affiliation", title: "@Resources.Affiliation", align: "center", sortable: true, width: 300 },
				{ field: "address", title: "@Resources.Address", align: "center", sortable: true, width: 300},
				{ field: "country", title: "@Resources.Country", align: "center", sortable: true, width: 150 },
				{ field: "state", title: "@Resources.State", align: "center", sortable: true, width: 150 },
				{ field: "city", title: "@Resources.City", align: "center", sortable: true, width: 150 },
				{ field: "zipCode", title: "@Resources.ZipCode", align: "center", sortable: true, width: 150 },
				{ field: "mail", title: "@Resources.Mail", align: "center", sortable: true, width: 250 },
				{ field: "telephone", title: "@Resources.Telephone", align: "center", sortable: true, width: 150 },
				{ field: "birthdate", title: "@Resources.Birthday", align: "center", sortable: true, width: 150 },
				{ field: "gender", title: "@Resources.Gender", align: "center", sortable: true, width: 150 },
				{ field: "passportNum", title: "@Resources.PassportNum", align: "center", sortable: true, width: 200 },
				{ field: "issueOfCountry", title: "@Resources.CountryOfIssue", align: "center", sortable: true, width: 200 },
				{ field: "dateOfIssue", title: "@Resources.DateOfIssue", align: "center", sortable: true, width: 200 },
				{ field: "expiryDate", title: "@Resources.ExpiryDate", align: "center", sortable: true, width: 200 },
				{ field: "arrivalDate", title: "@Resources.ArriveTime", align: "center", sortable: true, width: 150 },
				{ field: "departuralDate", title: "@Resources.DepartureTime", align: "center", sortable: true, width: 150 },
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 150,
					formatter: function(value, rec) {
						if (value == "@ConstValues.SendStatus.已发送") {
							return "@Resources.HasSend";
						} else if (value == "@ConstValues.InvitationStatus.已申请") {
							return "@Resources.HasInvitated";
						} else {
							return "@Resources.HasNotInvitated";
						}
					}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 150 },
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 150 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 }
			]],
			onBeforeLoad: function (param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			width: $(window).width() - 285,
			height: 822,
			left: ($(window).width() - windowWidth) * 0.5,
			top: ($(window).height() - windowHeight) * 0.5
		});

		$("#uploadWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
	});

	function searchData() {
		$("#dataGrid").datagrid("load", {
			SelUserName: $("#selUserName").textbox("getValue")
		});
	}

	function deleteData(id, userName) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, userName);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(ConferenceVisaController.Delete),
						nameof(ConferenceVisaController).GetControllerName())",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							setTimeout(function () {
								$("#dataGrid").datagrid("reload");
							}, 2000);
						}
					}
				);
			}
		});
	}

	function upload(id, attendenceId, conferenceId) {
		var confirmMessage = "@Resources.Upload";
		$("#hiddenID").val(id);
		$("#attendenceId").val(attendenceId)
		$("#conferenceId").val(conferenceId)
		$("#invitation").filebox("clear")
		$("#uploadWindow").window("open");
	}

	function uploadFile() {
		var filename = $("#invitation").filebox("getText")

		if (!/\.(doc|docs|docx|pdf|DOC|DOCS|DOCX|PDF)$/.test(filename)) {
			common.showError("@Resources.MsgDocumentType");
			return;
		}
		var confirmMessage = "@Resources.UploadFile";
		$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
			if (r) {
				var loading = layer.load(0,  {
					shade: [0.4,"#fff"]
				});

				$("#uploadDetail").form({
					iframe: false,
					success: function (data) { }
				});

				$("#uploadDetail").form("submit", {
					onSubmit: function (param) {
						param.random = Math.random();
					},
					success: function (data) {
						layer.close(loading);
						data = JSON.parse(data);
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#uploadWindow").window("close");
							$("#dataGrid").datagrid("reload");
						}
					},
				});

			}
		});
	}

	function lookup(attendId) {
		var url = "@Url.Action(nameof(ConferenceVisaController.GetVisaData), nameof(ConferenceVisaController).GetControllerName())" + "?attendId=" + attendId;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxSuccessResult") {
				$("#v-familyname").textbox("setValue", data.data.familyName);
				$("#v-firstname").textbox("setValue", data.data.firstName);

				$("#v-title").combobox({
					url: "@Url.Action(nameof(UtilityController.GetTitle), nameof(UtilityController).GetControllerName())?conferenceId=@Model.ConferenceId",
					valueField: "id",
					textField: "name",
					required: true,
					editable: false,
					panelHeight: "auto",
				});
				$("#v-title").combobox("setValue", data.data.title);

				$("#v-country").combobox({
					url: "@Url.Action(nameof(UtilityController.GetCountryEn), nameof(UtilityController).GetControllerName())",
					valueField: "id",
					textField: "name",
					required: true,
					//editable: false,
					onSelect: function (rec) {
						$("#v-city").combobox("clear");
						$("#v-city").combobox("loadData", {});
						$("#v-state").combobox({
							url: "@Url.Action(nameof(UtilityController.GetStateEn), nameof(UtilityController).GetControllerName())" + "/" + rec.id,
							valueField: "id",
							textField: "name",
							//editable: false,
							onSelect: function (record) {
								$("#v-city").combobox({
									url: "@Url.Action(nameof(UtilityController.GetCityEn), nameof(UtilityController).GetControllerName())" + "/" + record.id,
									valueField: "id",
									textField: "name",
									//editable: false,
								});
							}
						});
					}
				});
				$("#v-country").combobox("setValue", data.data.country);

				$("#v-state").combobox({
					url: "@Url.Action(nameof(UtilityController.GetStateEn), nameof(UtilityController).GetControllerName())" + "/" + data.data.country,
					valueField: "id",
					textField: "name",
					editable: false,
					onSelect: function (record) {
						$("#v-city").combobox({
							url: "@Url.Action(nameof(UtilityController.GetCityEn), nameof(UtilityController).GetControllerName())" + "/" + record.id,
							valueField: "id",
							textField: "name",
							editable: false,
						});
					}
				});
				$("#v-state").combobox("setValue", data.data.state);

				$("#v-city").combobox({
					url: "@Url.Action(nameof(UtilityController.GetCityEn), nameof(UtilityController).GetControllerName())" + "/" + data.data.state,
					valueField: "id",
					textField: "name",
					editable: false,
				});
				$("#v-city").combobox("setValue", data.data.city);

				$("#v-postcode").textbox("setValue", data.data.zipCode);
				$("#v-affiliation").textbox("setValue", data.data.affiliation);
				$("#v-email").textbox("setValue", data.data.mail);
				$("#v-telephone").textbox("setValue", data.data.tele);
				$("#v-birthdate").datebox("setValue", data.data.birthday);
				$("#v-gender").textbox("setValue", data.data.gender ? "Male":"Female");
				$("#v-address").textbox("setValue", data.data.address);
				$("#v-countryOfIssue").textbox("setValue", data.data.issueOfCountry);
				$("#v-passportNum").textbox("setValue", data.data.passportNum);
				$("#v-issueDate").datebox("setValue", data.data.dateOfIssue);
				$("#v-expiryDate").datebox("setValue", data.data.expiryDate);
				$("#v-arrivalDate").datebox("setValue", data.data.arrivalDate);
				$("#v-departuralDate").datebox("setValue", data.data.departuralDate);
				$("#v-remark").textbox("setValue", data.data.remark);
				$("#conferenceAttendId").val(attendId);

				$("#detailWindow").window("open");
			};
		});
	}

	function send(id, attendenceId, conferenceId) {
		var confirmMessage = "@Resources.CfmSendVisa";
		$.messager.confirm("@Resources.Send", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(ConferenceVisaController.SendMail),
						nameof(ConferenceVisaController).GetControllerName())",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							setTimeout(function () {
								$("#dataGrid").datagrid("reload");
							}, 2000);
						}
					}
				);
			}
		});
	}
</script>
}